function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    {
    c_start=c_start + c_name.length+1;
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length;
    return unescape(document.cookie.substring(c_start,c_end));
    }
  }
}
function calculate()
{   
	var Request = getCookie("Request");
	
	var count_elements = 0;
	var position = 0;
	var next_position=0;
	while( next_position != -1)
	{
		next_position = Request.indexOf("||", position+1);													//"||" is used as a tokenizer for separation of different elements
		position = next_position;
		count_elements++;																					//Total elements stored in the count_elements variable
	}
	
	//var elements = new Array[count_elements];		
	var elements = new Array(count_elements);
	position = 0;
	
	for(var i=0; i<count_elements-1; i++)
	{
		elements[i] = Request.substring(position+2, Request.indexOf("||", position+1));
		position = Request.indexOf("||", position+1);														//Elements being stored in the array
		
	}
	
	elements[count_elements-1] = Request.substring(position+2, Request.length);
	
	var elements_subparts = new Array(count_elements);
	for(var i=0;i<10;i++)
		{
		 elements_subparts[i]=new Array(10);
		}
	
	for(var i=0; i<count_elements; i++)
	{
		for(var j=0; j<10; j++)
			elements_subparts[i][j] = "\0";
		var sep_count = 0;
		var next_sep_position = 0;
		while(next_sep_position != -1)
		{
			next_sep_position = elements[i].indexOf("|", next_sep_position+1);
			sep_count++;
		}
		 sep_startPosition = -1;
		for(var k=0; k<sep_count-1; k++)
		{
			elements_subparts[i][k] = elements[i].substring(sep_startPosition+1, elements[i].indexOf("|", sep_startPosition+1));
			sep_startPosition = elements[i].indexOf("|", elements[i].indexOf("|", sep_startPosition+1));
		}
		elements_subparts[i][sep_count-1] = elements[i].substring(sep_startPosition+1, elements[i].length);
	}
	var cases=new Array(count_elements);
	var max_testcases = 0;																					//Used for counting maximum possible cases for any element
	for(var i=0; i<count_elements; i++)
	{
		 cases[i] = 0;	
			//User for storing maximum possible cases for a particular element
		if(elements_subparts[i][1]=="Textfield")
		{
			
			if(elements_subparts[i][2]=="Integer")													//If textfield is of type "eger"
			{;
				var Range_from = parseInt(elements_subparts[i][3]);									//Parameter Range_From for that particular variable 
				
				var Range_to = parseInt(elements_subparts[i][4]);									//Parameter Range_To for that particular variable 
				
				var isempty = parseInt(elements_subparts[i][5]);									//Parameter IsEmpty for that particular variable 
				
				cases[i] = Range_to - Range_from + 1 + isempty;												//maximum possible cases for that particular element.
																		//Checked if value of cases is greater than max_testcases. if it is so, then max_testcases is changed with the value of cases.
				
			}
			else if(elements_subparts[i][2]=="Double")												//If textfield is of type "Double"
			{
				var Range_from = parseFloat(elements_subparts[i][3]);							//Parameter Range_From for that particular variable
				var Range_to = parseFloat(elements_subparts[i][4]);								//Parameter Range_To for that particular variable
				var isempty = parseInt(elements_subparts[i][5]);									//Parameter IsEmpty for that particular variable
				var DecimalPlaces = parseFloat(elements_subparts[i][6]);							//Parameter DecimalPlaces used to store no of allowed possible digits after decimal.
				var local = parseInt((Range_to-Range_from)*Math.pow(10, DecimalPlaces));
				cases[i] =local + isempty + 1;															//maximum possible cases for that particular element.
																	//Checked if value of cases is greater than max_testcases. if it is so, then max_testcases is changed with the value of cases.
				
			}
			else if(elements_subparts[i][2]=="String")												//If textfield is of type "String"
			{
				var Range_from =parseInt(elements_subparts[i][3]);									//Parameter Range_From for that particular variable
				var Range_to = parseInt(elements_subparts[i][4]);									//Parameter Range_To for that particular variable
				var isempty =parseInt(elements_subparts[i][5]);									//Parameter IsEmpty for that particular variable
				var onlyAlpha = parseInt(elements_subparts[i][6]);									//Parameter used to store if value of Only Alphabets is true or false
				var alphaSpecial = parseInt(elements_subparts[i][7]);								
				var alphaNum = parseInt(elements_subparts[i][8]);									
				var alphaNumSpl =parseInt(elements_subparts[i][9]);								
				
																					
				if(alphaNumSpl==1)
				{
						for(var r=Range_from; r<=Range_to; r++)
						cases[i]+=Math.pow(43,r);
				}
				else if(alphaNumSpl==0 && alphaNum==1)
				{
						for(var r=Range_from; r<=Range_to; r++)
						cases[i]+=Math.pow(36,r);
				}
				else if(alphaNumSpl==0 && alphaNum==0 && alphaSpecial==1)
				{
					for(var r=Range_from; r<=Range_to; r++)
						cases[i]+=Math.pow(33,r);
				}
				else if(alphaNumSpl==0 && alphaNum==0 && alphaSpecial==0 && onlyAlpha==1)
					{
					for(var r=Range_from; r<=Range_to; r++)
						cases[i]+=Math.pow(26,r);
					}
				cases[i] += isempty;
																	
				
			}
		}
			else if(elements_subparts[i][1]=="Radio")											
			{
				var CommaPosition = 0;																		
				var next_CommaPosition=0;
				var NoOfComma = 0;																				
				while( next_CommaPosition != -1)
				{
					next_CommaPosition = elements_subparts[i][2].indexOf(",", CommaPosition+1);
					CommaPosition = next_CommaPosition;
					NoOfComma++;																			
				}
				cases[i]=NoOfComma;
																			
				
			}
			else if(elements_subparts[i][1]=="SelectList")												
			{
				var CommaPosition = 0;																		
				var next_CommaPosition=0;
				var NoOfComma = 0;																				
				while( next_CommaPosition != -1)
				{
					next_CommaPosition = elements_subparts[i][2].indexOf(",", CommaPosition+1);
					CommaPosition = next_CommaPosition;
					NoOfComma++;																			
				}
				cases[i]=NoOfComma;
																					
				
			}
			else if(elements_subparts[i][1]=="CheckBox")													
			{
				var CommaPosition = 0;																			
				var next_CommaPosition=0;															
				var NoOfComma = 0;
				if(elements_subparts[i][2]!="~")
					while( next_CommaPosition != -1)
				{
					next_CommaPosition = elements_subparts[i][2].indexOf(",", CommaPosition+1);
					CommaPosition = next_CommaPosition;
					NoOfComma++;																				
				}
				var totalPermutationCases = parseInt(Math.pow(2, parseFloat(NoOfComma)));			
				 cases[i] = totalPermutationCases;
																			
				
			}
		
		
		var totalCases = 1;
		
		for(var o=0;o<count_elements;o++)
		{   
			totalCases *= cases[o];
		}
	}
	return totalCases;
}
